Skip to content

feat(instagram): add Instagram integration#5568

Merged
BillLeoutsakosvl346 merged 22 commits into
stagingfrom
feature/instagram-integration
Jul 15, 2026
Merged

feat(instagram): add Instagram integration#5568
BillLeoutsakosvl346 merged 22 commits into
stagingfrom
feature/instagram-integration

Conversation

@BillLeoutsakosvl346

@BillLeoutsakosvl346 BillLeoutsakosvl346 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds Business Login OAuth, 23 tools, block, and publish routes for Instagram

Type of Change

  • New Feature

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Bill Leoutsakos and others added 3 commits July 9, 2026 17:25
Resolve UserFiles to Meta-fetchable presigned HTTPS URLs (600s TTL) via
internal publish routes, and fix OAuth scope storage plus connect-draft
wiring so Instagram Login publishing is testable end-to-end.

Co-authored-by: Cursor <cursoragent@cursor.com>
@vercel

vercel Bot commented Jul 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Jul 15, 2026 6:23pm

Request Review

@cursor

cursor Bot commented Jul 10, 2026

Copy link
Copy Markdown

PR Summary

High Risk
Touches OAuth token refresh and new Instagram auth/callback paths plus large third-party publishing surface; TikTok upload and webhook dispatch behavior also change in production.

Overview
Adds a full Instagram integration: dedicated OAuth authorize/callback (short- to long-lived token exchange, account persistence, credential drafts), proactive long-lived token refresh in shared OAuth helpers, env vars for Meta app credentials, a large workflow block (toolbar-hidden until approval) with many operations, server routes to publish image/video/reel/story/carousel and download media (carousel rollback, size limits), plus a cloud storage status API and UI gating when requiresCloudStorage is set so publish inputs need S3/Azure public URLs.

TikTok changes in the same PR: video draft upload now streams from storage with bounded chunking/retries instead of buffering the whole file; Direct Post returns 400 until per-post approval exists; webhook ingress fans out in fixed-size keyset pages with chained durable jobs. OAuth connect-draft creation is centralized in createConnectDraft for generic OAuth2 authorize and Instagram.

Reviewed by Cursor Bugbot for commit 952399a. Bugbot is set up for automated code reviews on this repo. Configure here.

Comment thread apps/sim/app/api/tools/instagram/publish-carousel/route.ts
Comment thread apps/sim/lib/integrations/instagram/resolve-media.ts
Comment thread apps/sim/tools/instagram/utils.ts
Comment thread apps/sim/blocks/blocks/instagram.ts
@greptile-apps

greptile-apps Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds Instagram integration support across OAuth, blocks, tools, and publishing routes. The main changes are:

  • Instagram Business Login OAuth and callback handling.
  • Instagram block registration and icon support.
  • Instagram media publish, download, messaging, profile, and insights tools.
  • File upload and cloud-storage support for Instagram publishing.
  • Tests and contract updates for the new Instagram and related media flows.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

Filename Overview
apps/sim/app/api/tools/instagram/publish-carousel/route.ts Adds the carousel publish route with child container creation, parallel child readiness checks, parent creation, and publish handling.
apps/sim/app/api/auth/oauth2/callback/instagram/route.ts Adds the Instagram OAuth callback flow with token exchange, profile lookup, account persistence, and credential draft processing.
apps/sim/app/api/auth/oauth/utils.ts Extends OAuth token helpers with Instagram proactive refresh handling.

Reviews (3): Last reviewed commit: "fix(instagram): drop hidden Instagram fr..." | Re-trigger Greptile

Comment thread apps/sim/app/api/tools/instagram/publish-carousel/route.ts Outdated
Comment thread apps/sim/app/api/auth/oauth2/callback/instagram/route.ts Outdated
…s, extend poll window and insights periods, use canonical user_id in OAuth callback
Comment thread apps/sim/tools/instagram/utils.ts Outdated
Comment thread apps/sim/app/api/auth/oauth2/callback/instagram/route.ts
…r_id

Co-authored-by: Cursor <cursoragent@cursor.com>
Comment thread apps/sim/tools/instagram/reply_to_comment.ts
Comment thread apps/sim/tools/instagram/utils.ts Outdated
Comment thread apps/sim/tools/instagram/get_conversation_messages.ts
…ts, request message timestamps explicitly

Co-authored-by: Cursor <cursoragent@cursor.com>
Comment thread apps/sim/tools/instagram/get_profile.ts Outdated
…trim() calls are safe

Co-authored-by: Cursor <cursoragent@cursor.com>
@BillLeoutsakosvl346

Copy link
Copy Markdown
Contributor Author

@greptile

Comment thread apps/sim/app/api/auth/oauth2/callback/instagram/route.ts
Match the official Instagram look by filling the tile with the orange–pink–purple radial gradient so the white camera glyph sits on a full-bleed brand background.

Co-authored-by: Cursor <cursoragent@cursor.com>
Default Reel share-to-feed to Yes, drop unused media fields params, share publish transform helpers, and warn when cloud storage is missing for Meta-fetchable uploads.

Co-authored-by: Cursor <cursoragent@cursor.com>
Treat loading/error as blocked for requiresCloudStorage uploads, show the warning once the check finishes, and disable selecting local workspace files Meta cannot fetch.

Co-authored-by: Cursor <cursoragent@cursor.com>
Comment thread apps/sim/lib/oauth/oauth.ts
Meta only allows refreshing still-valid Instagram tokens, so refresh within 14 days of expiry (after the 24h age gate) instead of waiting until after accessTokenExpiresAt.

Co-authored-by: Cursor <cursoragent@cursor.com>
Comment thread apps/sim/lib/integrations/instagram/resolve-media.ts
Comment thread apps/sim/tools/instagram/index.ts
The staging merge dropped the opening /** on ProviderAuthConfig.clientIdParamName, which broke TypeScript parse in CI.

Co-authored-by: Cursor <cursoragent@cursor.com>
Wire /api/files/storage-status through a shared route contract so the
strict API validation audit stays at zero non-Zod routes after the new
Instagram cloud-storage check.

Co-authored-by: Cursor <cursoragent@cursor.com>
Drop public-URL paste hints from advanced fields and the cloud-storage banner so the UI mirrors Gmail attachments.

Co-authored-by: Cursor <cursoragent@cursor.com>
Instagram is hideFromToolbar so it is excluded from integrations.json;
the pinned slug map must not expect it until the block is visible again.

Co-authored-by: Cursor <cursoragent@cursor.com>
@icecrasher321

Copy link
Copy Markdown
Collaborator

bugbot run

@icecrasher321

Copy link
Copy Markdown
Collaborator

@greptile

Comment thread apps/sim/app/api/auth/instagram/authorize/route.ts Outdated
Comment thread apps/docs/components/icons.tsx
workflow: workflowRecord,
}))
const nextCursor = rows.at(-1)?.webhookId ?? null
const hasMore = rows.length === TIKTOK_WEBHOOK_TARGET_PAGE_SIZE

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TikTok page hasMore false positive

Low Severity

Keyset pagination uses limit(PAGE_SIZE) and sets hasMore when rows.length === PAGE_SIZE instead of fetching PAGE_SIZE + 1 to peek. When a delivery has exactly 100 matching rows, ingress enqueues a continuation page that returns no targets, adding avoidable job churn under the shared concurrency limit.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 30de5b1. Configure here.

Avoid orphan pending credential drafts when INSTAGRAM_CLIENT_ID is missing,
matching the Shopify authorize ordering.

Co-authored-by: Cursor <cursoragent@cursor.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

There are 3 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 952399a. Configure here.

pendingCredentialDraft.workspaceId,
],
set: { displayName, expiresAt, createdAt: now },
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale reconnect draft survives upsert

Medium Severity

createConnectDraft upserts on (userId, providerId, workspaceId) but does not reset credentialId, unlike the credential draft API which sets credentialId to null for new connects. Instagram authorize uses this helper whenever workspaceId is present, so an unexpired reconnect draft can make a new Copilot Instagram connect run as a reconnect and attach the wrong credential.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 952399a. Configure here.

return {
chunkSize: DEFAULT_CHUNK_SIZE,
totalChunkCount: Math.floor(totalBytes / DEFAULT_CHUNK_SIZE),
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Single-chunk TikTok size mismatch

Medium Severity

computeTikTokChunkPlan only sets chunkSize equal to totalBytes when the file is at most 10MB. For sizes in (10MB, 20MB), Math.floor yields totalChunkCount: 1 while chunkSize stays 10MB, so init metadata disagrees with the single uploaded range. TikTok expects chunk_size to match video_size for one-chunk uploads, so common draft uploads in that size band can fail at init or transfer.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 952399a. Configure here.

@BillLeoutsakosvl346 BillLeoutsakosvl346 merged commit e2ea49e into staging Jul 15, 2026
17 checks passed
@waleedlatif1 waleedlatif1 deleted the feature/instagram-integration branch July 15, 2026 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants